namespace ::

entry {
    ShowWindow({
        @use state = State[Pair[Int,Int]](Pair(777,999)),
        @use u1 = PlainButton('Update 1st'),
        @use u2 = PlainButton('Update 2nd'),
        @use Effect((state bind-update (u1.Clicks map-to { v => v.(First).Update({ n => (n + 1) }) }))),
        @use Effect((state bind-update (u2.Clicks map-to { v => v.(Second).Update({ n => (n + 1) }) }))),
        @use l1 = Label(CountEmits('1st', state.Value.First)),
        @use l2 = Label(CountEmits('2nd', state.Value.Second)),
        let list = {
            let o1 = (state.Value.First map { v => Pair('1st',v) }),
            let o2 = (state.Value.Second map { v => Pair('2nd',v) }),
            @map (p1,p2) = (o1 combine-latest o2),
            List(p1, p2)
        },
        @use lv = ListView(list, { (k,_) => k }, { (item,info) => {
            @use l = Label(CountEmits(info.Key, item)),
            ItemView { widgets: List(l.Widget) }
        }}),
        Window($('Projection'), Column(u1.Widget, u2.Widget, l1.Widget, l2.Widget, lv.Widget))
    })
}
function CountEmits[T] { tag String, o $[T] } $[String] {
    @map n = StartWith(0, { o | with-index() | map({ (_,i) => (i + 1) }) }),
    String(tag, ': ', n)
}


